<template>
	<view class="content">
		<view class="head">
			<u-navbar leftIcon="arrow-leftward" :placeholder='true' @leftClick="leftClick" title="訂單信息">
			</u-navbar>
		</view>
		<view class="dindan">
			<view class="dindan-no">
				<view class="no-l">
					{{quote.quote_sn}}
					<text class="coppy" @click="copyTextToClipboard(quote.quote_sn)">複製</text>
				</view>
				<view class="no-r">
					<view v-if="quote.complete_status==0||quote.complete_status==10" class="">
						{{quote.quote_status==0? "商戶未確認": "商戶已報價"}}

					</view>
					<view v-else class="">
						{{quote.complete_status==5? "未審批": "未通過"}}
					</view>
				</view>
			</view>
			<view class="">
				<view class="goods-detail" v-for="(item,index) in goods" :key="index">
					<view class="detail-left">
						<view class="goods-left">
							<view class="goods-img">
								<image :src="getFirstImageLink(item.goods_images)" mode="aspectFit"></image>
								<!-- <image :src="item.goodsImage" style="width: 150rpx;height: 140rpx;"></image> -->
							</view>
						</view>
						<view class="size">
							<view class="goods-title">{{item.goods_name}}</view>
							<view class="center">
								<text>{{item.attr_value}}</text>
								<text>x{{item.goods_number}}</text>
							</view>
							<view class="bottom">
								<text class="goods-price">MOP {{item.unit_price}}</text>
								<view class="detail-right">
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="details" style="padding-bottom: 144rpx;">
			<view class="details-item">
				<view>下單時間</view>
				<view>{{quote.createtime}}</view>
			</view>
			<view class="details-item">
				<view>客戶備註</view>
				<view>{{quote.postscript? quote.postscript: '暫無'}}</view>
			</view>
			<view class="details-item">
				<view>商家備註</view>
				<view>{{quote.to_buyer? quote.to_buyer: '暫無'}}</view>
			</view>
		</view>
		<view class="end">
			<view class="end-left">


			</view>
			<view class="end-right">
				<view class="end-price">
					<view style="display: flex;align-items: center;">
						總計：<view style="font-size: 30rpx;font-weight: bold;color: #4949C3;">MOP
							{{quote.order_amount}}
						</view>
					</view>
					<view style="font-size: 22rpx;font-weight: 500;color: #333333;">
						共{{getTotalGoodsNumber(goods)}}件
					</view>
				</view>
				<view class="btn" @click="Tosubmit">
					加入購物車
				</view>
			</view>

		</view>
	</view>

</template>

<script>
	import {
		quoteorderDetails,addquotecart
	} from '@/network/api/user.js'
	export default {
		data() {
			return {
				goods: [],
				log: [],
				quote: [],
				quote_id: ''
			}
		},
		onLoad(e) {
			console.log(e.quote_id);
			if (e.quote_id) {
				this.quote_id = e.quote_id
			}
		},
		onShow() {
			this.getquoteDetails()
		},
		methods: {
      copyTextToClipboard(textToCopy) {
        uni.setClipboardData({
          data: textToCopy,
          success() {
            uni.showToast({
              title: '已复制到剪切板',
              icon: 'none'
            });
          },
          fail() {
            uni.showToast({
              title: '复制失败',
              icon: 'none'
            });
          }
        });
      },
			async Tosubmit() {
				const from = this.goods.map(item => {
					return {
						rec_id: item.rec_id,
						quote_id: item.order_id,
						goods_number: item.goods_number,
						goods_id: item.goods_id,
						goods_images: item.goods_images,
						stock: item.stock,
						goods_attr_id: item.goods_attr_id,
						numbering: item.numbering,
						goods_sn: item.goods_sn,
						specification_numbering: item.specification_numbering
					}
				})
				let data = {
					lang: 'cn',
					goods: from,
					quote_sn: this.quote.quote_sn
				}
				const res = await addquotecart(data)
				if (res.data.code == 1) {
					uni.showToast({
						title: '加入購物車成功',
						icon: 'success',
						duration: 2000
					})
				}

			},
			getTotalGoodsNumber(item) {
				// 计算商品总数量
				return item.reduce((total, goods) => total + goods.goods_number, 0);
			},
			async getquoteDetails() {
				let data = {
					quote_id: this.quote_id
				}
				const res = await quoteorderDetails(data)
				this.goods = res.data.goods
				this.log = res.data.log
				this.quote = res.data.quote

			},
			leftClick(url) {
				// uni.navigateTo({
				// 	url: '/pages/mine/quotationCar/index',
				// })
				uni.navigateBack({
					delta: 1
				})
			}
		},

	}
</script>

<style lang="scss">
	page {

		background: #F5F6F9;
	}

	.content {
		position: relative;
		height: 100vh;

		.end {
			width: 100%;
			height: 110rpx;
			background-color: #fff;
			position: fixed;
			bottom: 0;
			left: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;

			&-left {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				display: flex;
				justify-content: space-between;
				padding: 0 30rpx;

				.end-flex {
					display: flex;
					align-items: center;
				}
			}

			&-right {
				margin-right: 32rpx;
				display: flex;

				.end-price {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					align-items: flex-end;

				}

				.btn {
					margin-left: 20rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					line-height: 0rpx;
					color: #FFFFFF;
					width: 170rpx;
					height: 80rpx;
					line-height: 80rpx;
					background: #645AED;
					border-radius: 30rpx;
				}

				.red {
					background: #ED0000;
				}

			}
		}

		.details {
			margin-top: 16rpx;
			background-color: white;
			padding: 32rpx;

			.details-item {
				margin-bottom: 24rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;
				display: flex;
				justify-content: space-between;

				.item-img {
					width: 178rpx;
					height: 178rpx;
					background-color: bisque;
				}
			}
		}

		.threebtn {
			width: 100vw;
			height: 110rpx;
			bottom: 0;
			background: #FFFFFF;
			border-radius: 0rpx;
			position: fixed;
			display: flex;
			justify-content: flex-end;
			align-items: center;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;

			.btn {
				margin-right: 25rpx;
				text-align: center;
				line-height: 60rpx;
				width: 170rpx;
				height: 60rpx;
				border: 1rpx solid #CBCBCB;
				border-radius: 20rpx;
			}

			.green {

				border: 1rpx solid #645AED;
				color: #645AED;
			}
		}

		.jiage {
			display: flex;
			flex-direction: column;
			justify-content: flex-end;
			align-items: flex-end;
			margin-top: 22rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
		}

		.dindan {
			margin-top: 16rpx;
			background: white;
			padding: 32rpx;

			.dindan-no {
				padding-bottom: 32rpx;
				border-bottom: 1rpx solid #F1F1F1;
				display: flex;
				justify-content: space-between;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;

				.no-l {
					.coppy {
						margin-left: 15rpx;
						padding: 3rpx 15rpx;
						border: 1rpx solid #DEDEDE;
						border-radius: 12rpx;
						font-size: 20rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #999999;
					}

					color: #3A3A3A;
				}

				.no-r {
					display: flex;
					align-items: center;
					color: #645AED
				}
			}

			.goods {
				line-height: 80rpx;
				background-color: #FFFFFF;

				&-detail {
					display: flex;
					padding: 16rpx 0;
					// margin: 0 32rpx;
					background-color: #fff;
					justify-content: space-between;
					align-items: center;

					.detail-left {
						display: flex;
						flex: 1;

						.goods-left {
							display: flex;
							align-items: center;

							.goods-img {
								width: 180rpx;
								height: 180rpx;
								background: #FFFFFF;
								border: 1rpx solid #DEDEDE;
								border-radius: 30rpx;
								display: flex;
								justify-content: center;
								align-items: center;

								image {
                  max-width: 90%;
                  max-height: 90%;
								}
							}
						}
					}

					.size {
						flex: 1;
						display: flex;
						justify-content: space-between;
						flex-direction: column;
						margin-left: 30rpx;

						.center {
							justify-content: space-between;
							display: flex;
							font-size: 22rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							margin-top: 8rpx;
						}

						.bottom {
							margin-top: 22rpx;
							display: flex;
							align-items: center;
							justify-content: space-between
						}

						.goods-title {
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #333333;
						}

						.goods-price {
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #4949C3;
						}
					}

					.detail-right {
						.stepper {
							display: flex;
							// align-items: center;
							vertical-align: middle;

							.stepper-value {
								margin: 0 20rpx;
								font-size: 24rpx;
								line-height: 43rpx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #333333;
							}

							.stepper-btn {
								image {
									width: 44rpx;
									height: 44rpx;
								}
							}
						}

						text {
							width: 50rpx;
							line-height: 50rpx;
							text-align: center;
							display: inline-block;
							background-color: #F7F7F7;
							margin-right: 10rpx;
						}

						.add {
							color: #FA4305;
							border-radius: 10rpx 30rpx 30rpx 10rpx;
							margin-right: 20rpx;
						}

						.subtract {
							border-radius: 30rpx 10rpx 10rpx 30rpx;
						}
					}
				}
			}

		}

		.address {
			padding: 32rpx;
			background-color: white;
			margin-top: 16rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;

			.bottom {

				font-weight: 500;
			}
		}
	}
</style>
